<?php

namespace App\Admin\Controllers;

use App\Models\Log;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class LogController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'App\Models\Log';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Log);
        $grid->model()->orderBy('id','desc');
        $grid->column('id', __('Id'));
        $grid->column('logs', __('返回结果'))->modal(function ($grid){
            return $grid->log;
        });

        $grid->column('status', __('Status'));
        $grid->column('user_id', __('User id'));
        $grid->column('type', __('Type'));
        $grid->column('created_at', __('时间'));
        $grid->disableCreateButton();
        $grid->actions(function ($actions){
            // 去掉删除
            $actions->disableDelete();

            // 去掉编辑
            $actions->disableEdit();

            // 去掉查看
            $actions->disableView();
        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Log::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('log', __('Log'));
        $show->field('status', __('Status'));
        $show->field('user_id', __('User id'));
        $show->field('type', __('Type'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Log);

        $form->text('log', __('Log'));
        $form->text('status', __('Status'));
        $form->number('user_id', __('User id'));
        $form->text('type', __('Type'));

        return $form;
    }
}
